#!/usr/bin/env bash

function checkPage() {
    url="$1"
    checkText="$2"
    currentTime=$(date +"%Y-%m-%d %H:%M:%S")

    website_content=$(curl -s "$url")
    if [[ $website_content == *"$checkText"* ]]; then
        echo "[Info] $currentTime $url 网站页面正常"
    else
       echo "[Warn] $currentTime $url 网站页面不正常，请检查页面"
       exit 1
    fi
#    statusCode=$(curl -s -o /dev/null -w "%{http_code}" "$url")
#    if [ "$statusCode" -eq 200 ]; then
#        echo "[Info] $currentTime $url 网站正在运行..."
#        website_content=$(curl -s "$url")
#        if [[ $website_content == *"$checkText"* ]]; then
#            echo "[Info] $currentTime $url 网站页面正常"
#        else
#            echo "[Warn] $currentTime $url 网站页面不正常，请检查页面"
#            exit 1
#        fi
#    else
#        echo "[Warn] $currentTime $url 网站宕机了，状态码: $statusCode"
#        exit 1
#    fi

}

## 检查 www.jiehelink.com
checkPage "https://book.aishangwei.net" "爱尚维"
